//
//  HomeSettingVC.m
//  XiJianChui
//
//  Created by Mac on 16/7/19.
//  Copyright © 2016年 FanShuHan. All rights reserved.
//

#import "HomeSettingVC.h"
#import "HomeSettingItem.h"
#import "HomeTableViewCell.h"

static NSString *settingCellID = @"settingCellID";
@interface HomeSettingVC ()

@property(nonatomic,strong) NSArray *modelArr;

@end

@implementation HomeSettingVC

//懒加载
- (NSArray *)modelArr {
    if (_modelArr == nil) {
        NSArray *modelArr = [NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"SettingItem.plist" ofType:nil]];
        NSMutableArray *arr = [NSMutableArray array];
        for (NSDictionary *dict in modelArr) {
            HomeSettingItem *model = [HomeSettingItem itemWithDict:dict];
            [arr addObject:model];
        }
        _modelArr = arr;
    }
    
    return _modelArr;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self addChangeAccountBtn];
    
    //注册cell
    [self.tableView registerNib:[UINib nibWithNibName:@"HomeTableViewCell" bundle:nil] forCellReuseIdentifier:settingCellID];
    self.automaticallyAdjustsScrollViewInsets = NO;
    
    //基本设置
    self.title = @"个人设置";
    UIColor *bjColor = QhColor(239, 239, 244);
    self.view.backgroundColor = bjColor;
    self.tableView.scrollEnabled = NO;
    self.tableView.contentInset = UIEdgeInsetsMake(64, 0, 0, 0);
}

#pragma mark - 添加底部切换账号按钮
- (void)addChangeAccountBtn {
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn setTitle:@"切换账号" forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    [btn setBackgroundColor:[UIColor whiteColor]];
    btn.frame = CGRectMake(0, 0, QhScreenW, 44);                                                                                                                                                                                                                                                                                                                                                                                   
    
//    [self.tableView.tableFooterView addSubview:btn];
    self.tableView.tableFooterView = btn;
}

#pragma mark - Table view data source
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 5;
}
//
//- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
//    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:settingCellID];
//    if (cell == nil) {
//        cell = [[HomeTableViewCell alloc] init];
//    }
////    cell.textLabel.text = @"我的资料";
//    
//    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
//    return cell;
//}

int tag1 = 0;
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:settingCellID];
    if (cell == nil) {
        cell = [[HomeTableViewCell alloc] init];
    }
    //    cell.textLabel.text = [NSString stringWithFormat:@"%ld,%ld",indexPath.section,indexPath.row];
    //    cell = (HomeTableViewCell *)cell;
    HomeTableViewCell *homeCell = (HomeTableViewCell *)cell;
    homeCell.model = self.modelArr[tag1];
    if (tag1 < 4) {
        tag1 += 1;
    }else {
        tag1 = 0;
    }
    
    return cell;
}


- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 10;
}


@end
